package com.ruoyi.energy.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.energy.domain.TcIn;
import com.ruoyi.energy.domain.vo.TcInWXVO;
import com.ruoyi.energy.mapper.TcInMapper;
import com.ruoyi.energy.service.ITcInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 进场回调Service业务层处理
 *
 * @author cjie
 * @date 2021-11-30
 */
@Service
public class TcInServiceImpl implements ITcInService {
    @Autowired
    private TcInMapper tcInMapper;

    /**
     * 查询进场回调
     *
     * @param parkId 进场回调ID
     * @return 进场回调
     */
    @Override
    public TcIn selectTcInById(String parkId) {
        return tcInMapper.selectTcInById(parkId);
    }

    /**
     * 查询进场回调列表
     *
     * @param tcIn 进场回调
     * @return 进场回调
     */
    @Override
    public List<TcIn> selectTcInList(TcIn tcIn) {
        return tcInMapper.selectTcInList(tcIn);
    }


    /**
     * 新增进场回调
     *
     * @param tcIn 进场回调
     * @return 结果
     */
    @Override
    public int insertTcIn(TcIn tcIn) {
        tcIn.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        tcIn.setCreateTime(DateUtils.getNowDate());
        tcIn.setCreateBy(SecurityUtils.getUsername());
        return tcInMapper.insertTcIn(tcIn);
    }

    /**
     * 修改进场回调
     *
     * @param tcIn 进场回调
     * @return 结果
     */
    @Override
    public int updateTcIn(TcIn tcIn) {
        return tcInMapper.updateTcIn(tcIn);
    }

    /**
     * 批量删除进场回调
     *
     * @param parkIds 需要删除的进场回调ID
     * @return 结果
     */
    @Override
    public int deleteTcInByIds(String[] parkIds) {
        return tcInMapper.deleteTcInByIds(parkIds);
    }

    /**
     * 删除进场回调信息
     *
     * @param parkId 进场回调ID
     * @return 结果
     */
    @Override
    public int deleteTcInById(String parkId) {
        return tcInMapper.deleteTcInById(parkId);
    }

    @Override
    public List<TcInWXVO> selectTcInWXVOnList(TcInWXVO tcIn) {
        TcIn search = BeanUtil.toBean(tcIn,TcIn.class);
        List<TcIn> tcIns = tcInMapper.selectTcInList(search);
        List<TcInWXVO> results = new ArrayList<>(tcIns.size());
        for(TcIn tcin:tcIns){
            results.add(BeanUtil.toBean(tcin,TcInWXVO.class));
        }
        return results;
    }
}
